<?php

namespace Products;

use Bank\BankUtils;

class ShortDeposit extends Deposit {
	const ONE_MONTH = 1;
	const ONE_MONTH_INTERESTRATE = 2.5;
	const THREE_MONTHS = 3;
	const THREE_MONTHS_INTERESTRATE = 3;
	const SIX_MONTHS = 6;
	const SIX_MONTHS_INTERESTRATE = 3.5;
	const NINE_MONTHS = 9;
	const NINE_MONTHS_INTERESTRATE = 4;
	const TWELVE_MONTHS = 12;
	const TWELVE_MONTHS_INTERESTRATE = 4.75;
	private $period;
	private $amount;
	private $interestRate;
	public function __construct($period, $amount) {
		$this->setPeriod ( $period );
		$this->setAmount ( $amount );
	}
	public function getPeriod() {
		return $this->period;
	}
	public function setPeriod($period) {
		if ($period == null) {
			throw new BaseException ( "Please enter short deposit period!", BaseException::CODE_1001 );
		}
		if (is_int ( $period ) == false) {
			throw new BaseException ( "Please enter number for short deposit period!", BaseException::CODE_1002 );
		}
		if ($period != 1 || $period != 3 || $period != 6 || $period != 9 || $period != 12) {
			throw new BaseException ( "Please enter - 1 month , 3 months , 6 months , 9 months or 12 months for your short deposit period !", BaseException::CODE_1003 );
		}
		
		if ($period == self::ONE_MONTH) {
			$this->period = $period;
			$this->setInterestRate ( self::ONE_MONTH_INTERESTRATE );
		}
		if ($period == self::THREE_MONTHS) {
			$this->period = $period;
			$this->setInterestRate ( self::THREE_MONTHS_INTERESTRATE );
		}
		if ($period == self::SIX_MONTHS) {
			$this->period = $period;
			$this->setInterestRate ( self::SIX_MONTHS_INTERESTRATE );
		}
		if ($period == self::NINE_MONTHS) {
			$this->period = $period;
			$this->setInterestRate ( self::NINE_MONTHS_INTERESTRATE );
		}
		if ($period == self::TWELVE_MONTHS) {
			$this->period = $period;
			$this->setInterestRate ( self::TWELVE_MONTHS_INTERESTRATE );
		}
	}
	public function getAmount() {
		return $this->amount;
	}
	public function setAmount($amount) {
		if ($amount == null) {
			throw new BaseException ( "Please enter short deposit amount!", BaseException::CODE_1004 );
		}
		if (is_double ( $amount ) != true) {
			throw new BaseException ( "Please enter XXX.XX amount!", BaseException::CODE_1005 );
		}
		
		$this->amount = $amount;
	}
	public function getInterestRate() {
		return $this->interestRate;
	}
	public function setInterestRate($interestRate) {
		$this->interestRate = $interestRate;
	}
	public function addInterest() {
		BankUtils::calculateDepositMonthlyPayment ( $this->getAmount (), $this->getInterestRate () );
	}
	public function showInfo() {
		echo '<p>Short Deposit</p>';
		echo '<p>Short Deposit - period : ' . $this->getPeriod () . '</p>';
		echo '<p>Short Deposit - amount : ' . $this->getAmount () . '</p>';
		echo '<p>Short Deposit - interest rate: ' . $this->getInterestRate () . ' % </p>';
		echo '<p>Short Deposit - monthly payment : ' . BankUtils::calculateDepositMonthlyPayment ( $this->getAmount (), $this->getInterestRate () * 10 ) . ' BGN</p>';
	}
}
?>